package cz.muni.fi.pb138.odsKartW;

import java.util.ArrayList;
import java.util.List;

/**
 * Class represents CD/DVD/BR medium with any content.
 * 
 * @author Michal Sorentíny
 * @version 05/05/2011
 */
public class Medium {
    
    private int ID;
    private String sheetLabel;

    private List<Title> titles;
    
    public Medium() {
        this.titles = new ArrayList<Title>();
    }
    
    /**
     * Constructor for new Medium with given sheetLabel and an empty list of titles.
     * 
     * @param label name of the medium
     */
    public Medium(String sheetLabel) {
        this.sheetLabel = sheetLabel;
        this.titles = new ArrayList<Title>();
    }
    
    /**
     * Constructor for new Medium with given ID and an empty list of titles.
     * 
     * @param label name of the medium
     */
    public Medium(int ID) {
        this.ID = ID;
        this.titles = new ArrayList<Title>();
    }
    
    /**
     * Constructor for a new medium with existing list of titles.
     * 
     * @param label name of the medium
     * @param titles list of titles on medium
     */
    public Medium(int ID, List<Title> titles) {
        if (titles == null) {
            throw new IllegalArgumentException("titles");
        }
        this.ID = ID;
        this.titles = titles;
    }
    
    public void setSheetLabel(String sheetLabel) {
        this.sheetLabel = sheetLabel;
    }

    public String getSheetLabel() {
        return sheetLabel;
    }
    
    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }
    
    public List<Title> getTitles() {
        return titles;
    }

    public void setTitles(List<Title> titles) {
        this.titles = titles;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Medium other = (Medium) obj;
        if (this.ID != other.getID()) {
            return false;
        }
        if ((this.sheetLabel == null) ? (other.sheetLabel != null) : !this.sheetLabel.equals(other.sheetLabel)){
            return false;
        }
        if (this.titles != other.titles && (this.titles == null || !this.titles.equals(other.titles))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + this.ID;
        hash = 79 * hash + (this.sheetLabel != null ? this.sheetLabel.hashCode() : 0);
        hash = 79 * hash + (this.titles != null ? this.titles.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        String titles = new String();
        for (Title title: this.getTitles()){
            titles = titles.concat(title.toString() + ";\n");
        }
        return "Medium{" + "Id = " + ID + ";\n SheetLabel = " + sheetLabel + ";\n Titles{ " + titles + "}}";
    }
    
}
